#include "OiPCH.hpp"
#include "ui_OiFlangeXCalibration.h"

namespace Oi { namespace Appl {

    class FlangeXCalibrationImpl : public Impl<FlangeXCalibration>, public Ui::UiFlangeXCalibration
    {
    public:
        void init(QObject* window);
        void exit();

    public:
        FlangeXWindow* _window;
    };

    void FlangeXCalibrationImpl::init(QObject* window)
    {
        OI_Q(FlangeXCalibration);

        setupUi(q);

        _window = qobject_cast<FlangeXWindow*>(window);

        auto setting = Core::OiSettings();

        QString head = "_d19";
        for (auto child : tabD19->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            child->setValue(setting->value(name).toDouble());
        }

        head = "_4d25";
        for (auto child : tab4D25->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            child->setValue(setting->value(name).toDouble());
        }

        head = "_bock615";
        for (auto child : tabBock615->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            child->setValue(setting->value(name).toDouble());
        }

        head = "_cam";
        for (auto child : tabCamera->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            child->setValue(setting->value(name).toDouble());
        }

        head = "_markBlock";
        for (auto child : tabMarkBlock->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            child->setValue(setting->value(name).toDouble());
        }
    }

    void FlangeXCalibrationImpl::exit()
    {
    }

    FlangeXCalibration::FlangeXCalibration(QObject* window, QWidget* parent /* = NULL */) : Ctrl::Dialog(parent)
    {
        OI_I(FlangeXCalibration)->init(window);
    }

    FlangeXCalibration::~FlangeXCalibration()
    {
        OI_E(FlangeXCalibration)->exit();
    }

    void FlangeXCalibration::accept()
    {
        OI_F(FlangeXCalibration);

        auto setting = Core::OiSettings();

        QString head = "_d19";
        for (auto child : d->tabD19->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            setting->setValue(name, child->getValue());
        }

        head = "_4d25";
        for (auto child : d->tab4D25->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            setting->setValue(name, child->getValue());
        }

        head = "_bock615";
        for (auto child : d->tabBock615->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            setting->setValue(name, child->getValue());
        }

        head = "_markBlock";
        for (auto child : d->tabMarkBlock->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            setting->setValue(name, child->getValue());
        }

        head = "_cam";
        for (auto child : d->tabCamera->findChildren<Ctrl::Double*>())
        {
            QString name = head + child->property("tag").toString();
            setting->setValue(name, child->getValue());
        }

        Ctrl::Dialog::accept();
    }

    void FlangeXCalibration::reject()
    {
        Ctrl::Dialog::reject();
    }
}}

